package com.wf.course.web.controller.goods;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.utils.export.GoodsBillExcelExporter;
import com.utils.page.PageBean;
import com.wf.course.model.bill.Bill;
import com.wf.course.service.IBillService;
import com.wf.course.web.Interceptor.LogInfo;
/**
 * 
 * @content 列表Controller
 */
@RequestMapping("goodsBill")
@Controller
public class GoodsBillController {

	@Autowired
	private IBillService billService;
	 

	/**
	 * 对账单列表展示
	 * @param pageNo
	 * @param pageSize
	 * @param tradetype
	 * @param tradestatus
	 * @param model
	 * @return
	 */
	@RequestMapping("goodsBillList")
	public String goodsInfoList(@RequestParam(value = "pageNo", required = false) Integer pageNo,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "tradetype", required = false) String tradetype, 
			@RequestParam(value = "tradestatus", required = false) String tradestatus, 
			@RequestParam(value = "tradeBeginTime", required = false) String tradeBeginTime, 
			@RequestParam(value = "tradeEndTime", required = false) String tradeEndTime, 
			Model model) {

		// 组装一个查询条件的map
		Map<String, Object> cons = new HashMap<String, Object>();
		 
		if(tradetype!=null && tradetype!=""){
			cons.put("tradetype", tradetype);
		}
		if(tradestatus!=null && tradestatus!=""){
			cons.put("tradestatus", tradestatus);
		}
		if(tradeBeginTime!=null && tradeBeginTime!=""){
			cons.put("tradeBeginTime", tradeBeginTime);
		}
		if(tradeEndTime!=null && tradeEndTime!=""){
			cons.put("tradeEndTime", tradeEndTime);
		}
		 
		
		PageBean<Bill> pageBean = new PageBean<Bill>(pageNo, pageSize, null, cons);
		pageBean.setUrl("goodsBill/goodsBillList");
		this.billService.indexInfo(pageBean);
		
		model.addAttribute("page", pageBean);
		return "goods/goodsBillList";
	}

	
	 /**
	   * 对账单导出
	   * @return
	   */
	@LogInfo("微信账单导出")
	@RequestMapping(value="exportExcel"  , method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public void exportExcel(HttpServletRequest request, 
			@RequestParam(value = "tradetype", required = false) String tradetype, 
			@RequestParam(value = "tradestatus", required = false) String tradestatus, 
			@RequestParam(value = "tradeBeginTime", required = false) String tradeBeginTime, 
			@RequestParam(value = "tradeEndTime", required = false) String tradeEndTime, 
			HttpServletResponse response,
			Model model){
         
			// 组装一个查询条件的map
			Map<String, Object> cons = new HashMap<String, Object>();
			 
			if(tradetype!=null && tradetype!=""){
				cons.put("tradetype", tradetype);
			}
			if(tradestatus!=null && tradestatus!=""){
				cons.put("tradestatus", tradestatus);
			}
			if(tradeBeginTime!=null && tradeBeginTime!=""){
				cons.put("tradeBeginTime", tradeBeginTime);
			}
			if(tradeEndTime!=null && tradeEndTime!=""){
				cons.put("tradeEndTime", tradeEndTime);
			}
			 
	  		PageBean<Bill> pageBean = new PageBean<Bill>(null, null, null, cons);	  		
	  		 
	  		List<Bill> billList = this.billService.getBills(pageBean);
	  		
	  		if(billList!=null && billList.size()>0){
	  			
			// 实例化表以Excel格式的导出工具
			GoodsBillExcelExporter dosExcelExporter = new GoodsBillExcelExporter();
			// 执行导出操作
				dosExcelExporter.exportExcel(response, billList);
			 
		
	  			
	  		}    
		
	}

	

}
